package com.zjdiepu.www.proxy.biz.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diepu.www.client.hzicbc.proxy.request.PublicRequest;
import com.diepu.www.client.hzicbc.proxy.request.common.PicInfo;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.config.FileProxyConfig;
import com.zjdiepu.www.config.HzicbcConfig;
import com.zjdiepu.www.config.QiniuProperty;
import com.zjdiepu.www.config.ScheduleProxyConfig;
import com.zjdiepu.www.proxy.biz.own.LogsBiz;
import com.zjdiepu.www.proxy.biz.transfer.ITransferYwOrdernoBankService;
import com.zjdiepu.www.proxy.dao.transfer.TransferDzApplyDiviMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferLogsMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferLogsSubMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferOtherAttachmentsMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferOtherTimedTaskMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwBusinessBuyerMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwBusinessCarMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwBusinessLoanMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwOpenCardHzicbcMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwOpenCardHzicbcSubMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferYwOrdernoBankMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferZxQueryCreditApplyMapper;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferOtherAttachments;
import com.zjdiepu.www.service.hzicbc.IHzicbcService;
import com.zjdiepu.www.service.partner.IDiepuService;
import com.zjdiepu.www.util.SerialNoUtil;
/**
 * 公共方法
 * @author xiongxiaotun
 *
 */
@Service
public class BaseProxyService {
	@Resource
	protected QiniuProperty qiniuProperty;
	@Resource
	protected HzicbcConfig hzicbcConfig;
	@Resource
	protected FileProxyConfig fileProxyConfig;
	@Resource
	protected ScheduleProxyConfig scheduleProxyConfig;
	@Resource
	protected TransferLogsMapper transferLogsMapper;
	@Resource
	protected TransferLogsSubMapper transferLogsSubMapper;
	@Resource
	protected TransferDzApplyDiviMapper transferDzApplyDiviMapper;
	@Resource
	protected TransferOtherTimedTaskMapper transferOtherTimedTaskMapper;
	@Autowired
	protected TransferZxQueryCreditApplyMapper transferZxQueryCreditApplyMapper;
	@Autowired
	protected TransferYwOrdernoBankMapper transferYwOrdernoBankMapper;
	@Autowired
	protected ITransferYwOrdernoBankService transferYwOrdernoBankService;
	@Autowired
	protected TransferYwBusinessBuyerMapper transferYwBusinessBuyerMapper;
	@Autowired
	protected TransferYwBusinessCarMapper transferYwBusinessCarMapper;
	@Autowired
	protected TransferYwBusinessLoanMapper transferYwBusinessLoanMapper;
	@Autowired
	protected TransferOtherAttachmentsMapper transferOtherAttachmentsMapper;
	@Autowired
	protected TransferYwOpenCardHzicbcMapper transferYwOpenCardHzicbcMapper;
	@Autowired
	protected TransferYwOpenCardHzicbcSubMapper transferYwOpenCardHzicbcSubMapper;
	
	@Autowired
	protected IHzicbcService hzicbcService;
	@Autowired
	protected IDiepuService diepuService;
	
	@Resource
	protected LogsBiz logsBiz;
	
	/**
	 * 获取附件
	 * @param transferOtherAttachments
	 * @return
	 */
	public PicInfo getPicInfo(TransferOtherAttachments transferOtherAttachments) {
		PicInfo picInfo = new PicInfo();
		picInfo.setPicid(transferOtherAttachments.getPicid());
		picInfo.setPicurl(fileProxyConfig.getGateWayNginx() + transferOtherAttachments.getLocalFilePath() + "?imageName=" + transferOtherAttachments.getFileName());
		picInfo.setPicnote(transferOtherAttachments.getFileName());
		return picInfo;
	}
	
	/**
	 * 获取附件
	 * @param transferOtherAttachments
	 * @return
	 */
	public List<PicInfo> getPicInfos(List<TransferOtherAttachments> transferOtherAttachments) {
		List<PicInfo> picInfos = new ArrayList<PicInfo>();
		if(CollectionUtils.isEmpty(transferOtherAttachments)) {
			return picInfos;
		}
		for(TransferOtherAttachments transferOtherAttachment : transferOtherAttachments) {
			if(null != transferOtherAttachment) {
				picInfos.add(getPicInfo(transferOtherAttachment));
			}
		}
		return picInfos;
	}
	
	/**
	 * 公共参数：基础
	 * @param busiId
	 * @param zoneno
	 * @return
	 */
	public PublicRequest preparedPub(String orderno, String zoneno) {
		Date now = new Date();
		PublicRequest pub = new PublicRequest();
		pub.setPlatno(hzicbcConfig.getPlatno());
		pub.setCmpseq(SerialNoUtil.createBankSerialNo());
		pub.setZoneno(zoneno);
		pub.setPhybrno(hzicbcConfig.getPhybrno());
		pub.setOrderno(orderno);
		pub.setAssurerno(hzicbcConfig.getAssurerno());
		pub.setCmpdate(DateUtil.dateTo8Str(now));
		pub.setCmptime(DateUtil.dateTo6Str(now));
		return pub;
	}
	/**
	 * 公共参数：分期
	 * @param busiId
	 * @param zoneno
	 * @return
	 */
	public PublicRequest preparedDiviPub(String orderno, String zoneno, String busitype) {
		Date now = new Date();
		PublicRequest pub = new PublicRequest();
		pub.setPlatno(hzicbcConfig.getPlatno());
		pub.setCmpseq(SerialNoUtil.createBankSerialNo());
		pub.setZoneno(zoneno);
		pub.setPhybrno(hzicbcConfig.getPhybrno());
		pub.setOrderno(orderno);
		pub.setAssurerno(hzicbcConfig.getAssurerno());
		pub.setCmpdate(DateUtil.dateTo8Str(now));
		pub.setCmptime(DateUtil.dateTo6Str(now));
		pub.setBusitype(busitype);
		return pub;
	}
	/**
	 * 公共参数:面签
	 * @param busiId
	 * @param zoneno
	 * @return
	 */
	public PublicRequest preparedInterviewPub(String orderno) {
		Date now = new Date();
		PublicRequest pub = new PublicRequest();
		pub.setPlatno(hzicbcConfig.getPlatno());
		pub.setCmpseq(SerialNoUtil.createBankSerialNo());
		pub.setGuestPlatno(hzicbcConfig.getPlatno());
		pub.setOrderno(orderno);
		pub.setCmpdate(DateUtil.dateTo8Str(now));
		pub.setCmptime(DateUtil.dateTo6Str(now));
		return pub;
	}
}
